﻿using System;
using System.Data;
using System.Data.SqlClient;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Control_DoiMatKhau : System.Web.UI.UserControl
{
    XuLy xl = new XuLy();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["DangNhap"]!=null)
        {
            KetNoi kn = new KetNoi();
             //string query = "select MatKhau from KhachHang where TenDN='" + Session["DangNhap"].ToString() + "'";
            //DataTable query = xl.Load("select MatKhau from KhachHang where TenDN='" + Session["DangNhap"].ToString() + "'");
            //string mkCu = Convert.ToString(query.Rows[0][0].ToString());
            txtTenDangNhap.Text = Session["DangNhap"].ToString();
            //txtMatKhauCu.Text = mkCu;

        }
    }
    protected void btnLamLai_Click(object sender, EventArgs e)
    {
        txtMatKhauCu.Text = "";
        txtMatKhauMoi.Text = "";
        txtNhapLaiMKMoi.Text = "";
    }
    protected void btnDongY_Click(object sender, EventArgs e)
    {
        DataTable query  = xl.Load("select MatKhau from KhachHang where TenDN='" + Session["DangNhap"].ToString() + "'");
       // string query = "select MatKhau from KhachHang where TenDN='" + Session["DangNhap"].ToString() + "'";// lay mat khau tron co so du lieu ra
        string mkCu = Convert.ToString(query.Rows[0][0].ToString()); // Convert.ToDouble(taikhoan.Rows[0][0].ToString());
        string MKCu = txtMatKhauCu.Text ;
        if (MKCu == mkCu)
        {
           
            string MKMoi =Convert.ToString( txtMatKhauMoi.Text);
            //string query4 = "update Khachhang set taikhoan=" + tienthem + " where tendn='" + Session["DangNhap"].ToString() + "'";
            string query1 = "update KhachHang set MatKhau='" + MKMoi + "' where TenDN='" + Session["DangNhap"].ToString() + "'";
            xl.XuLyDuLieu(query1);
            Response.Redirect("BaoLoi.aspx?mod=ChangePassword");

        }
        else
        {
            Response.Write("<script> alert('Mật Khẩu Cũ Của Bạn Bị Sai!!!') ;</script>");
        }
    }
}